import Vue from "vue"
import Vuex from "vuex"
//uniapp 内置的插件
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		testName: '测试',
		historyList:[],//搜索历史记录
		searchList:[],//搜索结果，组件嵌套组件太麻烦了，
		searchLoading:false,//搜索loading  状态  
		paramIndex:0,//触底加载方法，
		
	},
	getters:{
		// 取历史记录
		getHisList(state){
			return state.historyList
		},
		getSeaList(state){
			return state.searchList
		},
		getSeaLoad(state){
			return state.searchLoading
		},
		getPaIndex(state){
			return state.paramIndex
		}
		
	},
	mutations:{
		// 修改历史
		saveHisList(state,payload){
			state.historyList = payload
		},
		saveSeaList(state,payload){
			state.searchList = payload
		},
		saveSeaLoad(state,payload){
			state.searchLoading = payload
		},
		savePaIndex(state,payload){
			state.paramIndex = payload
		},
		
	},
	actions:{
		// 异步
		setHisList({commit,state},payload){
			let list = state.historyList
			list.unshift(payload)
			commit('saveHisList',list)
		},
		// 异步处理数组  
		setSeaList({commit,state},payload){
			let tempSea = state.searchList;
			// let tempNew = tempSea.concat(payload);
			// console.log(tempNew)
			commit('saveSeaList',tempSea.concat(payload))
		}
	}
})

export default store
